﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace StudentRegistration
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string firstName = txtFirstName.Text;
            string lastName = txtLastName.Text;
            int facultyNumber = 0;
            string university = lstUniversities.SelectedValue;
            string specialty = lstSpecialty.SelectedValue;

            StringBuilder courses = new StringBuilder();
            foreach (ListItem item in lstCourses.Items)
            {
                if (item.Selected)
                {
                    courses.Append(item.Value);
                    courses.Append(", ");
                }
            }

            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName)
                || !Int32.TryParse(txtFacultyNumber.Text, out facultyNumber))
            {
                lblMessage.Text = "Invalid input!<br />";
            }
            else
            {
                lblMessage.Text = "<h1>Student Summary</h1>" +
                             "<p><b>First Name:</b> " + Server.HtmlEncode(firstName) + "</p>" +
                             "<p><b>Last Name:</b> " + Server.HtmlEncode(lastName) + "</p>" +
                             "<p><b>Faculty Number:</b> " + facultyNumber + "</p>" +
                             "<p><b>University:</b> " + university + "</p>" +
                             "<p><b>Specialty:</b> " + specialty + "</p>" +
                             "<p><b>Courses:</b> " + courses.ToString() + "</p>";
            }
        }
    }
}